/**
 * 基地相关API
 */
import apiClient from './client';
import { CityBaseItem, CityBaseData, baseLicenseItem, baseTrafficItem, LicenseItem } from '../types/cityBase';

/**
 * 获取指定城市的基地列表
 * @param districts 行政区列表
 * @returns 基地列表
 */
export const getBasesByCityApi = async (
  districts: number[] | null = null
): Promise<{
    code: number;
    message: string;
    data: CityBaseItem[];
}> => {
  return apiClient.get('/api/base/v1/districts', {
    districts: districts?.join(',')
  });
};

/**
 * 获取指定城市的基地列表
 * @param districts 行政区列表
 * @returns 基地列表
 */
export const getBasesByCityCodeIdApi = async (cityCode: number): Promise<{
    code: number;
    message: string;
    data: CityBaseItem[];
}> => {
  return apiClient.get('/api/base/v1/city', {
    city_id: cityCode
  });
};

/**
 * 获取基地的驾照类型
 * @param bases 基地列表
 * @returns 基地执照信息
 */
export const getBaseLicensesApi = async (
  bases: number[] | null = null
): Promise<{
    code: number;
    message: string;
    data: baseLicenseItem;
}> => {
  return apiClient.get('/api/base/v1/licenses', {
    bases: bases?.join(',')
  });
};

/**
 * 获取基地交通信息
 * @param bases 基地ID列表
 * @returns 基地交通信息
 */
export const getBaseTrafficApi = async (
  bases: number[] | null = null
): Promise<{
    code: number;
    message: string;
    data: {[key: number]: baseTrafficItem};
}> => {
  return apiClient.get('/api/base/v1/traffic', {
    bases: bases?.join(',')
  });
};

/**
 * 获取基地详细信息
 * @param baseId 基地ID
 * @returns 基地详细信息
 */
export const getBaseDetailApi = async (baseId: number): Promise<{
    code: number;
    message: string;
    data: CityBaseData;
}> => {
  return apiClient.get(`/api/base/v1/base-info`, {base_id: baseId});
};


/**
 * 获取车辆执照数据
 * @returns 基地详细信息
 */
export const getCarLicensesApi = async (): Promise<{
    code: number;
    message: string;
    data: {[key: string]: LicenseItem};
}> => {
  return apiClient.get('/api/base/v1/car-license');
};